//
//  HLImageCollectionCell.m
//  s.
//
//  Created by fanshijian on 2022/9/2.
//  Copyright © 2022 J. All rights reserved.
//

#import "BEImageCollectionCell.h"
#import "UImageModel.h"

@interface BEImageCollectionCell ()

@property (weak, nonatomic) UIImageView *img;

@end

@implementation BEImageCollectionCell

- (UIImageView *)img {
    if (!_img) {
        UIImageView *obj = [UIImageView new];
        [self.contentView addSubview:_img = obj];
        [obj mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeEdge0;
        }];
        obj.contentMode = UIViewContentModeScaleAspectFill;
        obj.layer.masksToBounds = YES;
    }
    return _img;
}

- (void)setModel:(UImageModel *)model {
    if (self.model != model || model.modified) {
        [super setModel:model];
        if ([model.url hasPrefix:@"http"]) {
            if (model.placeholder) {
                self.img.kl_imageUrlBlock(model.url, U_imageNamed(model.placeholder));
            }else {
                self.img.kl_imageUrl = model.url;
            }
        }else {
            self.img.image = U_imageNamed(model.url);
        }
        
        if (model.imgMakerBlock) {
            [self.img mas_remakeConstraints:model.imgMakerBlock];
        }
    }
}

@end
